import 'package:flutter/material.dart';

import 'components/my_enable_text_field.dart';
import './components/my_editable_text.dart' as MyEdit;
import 'controller/key_controller.dart';
import 'controller/my_keyboard.dart';
import './controller/key_item.dart';

class MySelfField extends StatefulWidget {
  MySelfField({Key key}) : super(key: key);

  @override
  _MySelfFieldState createState() => _MySelfFieldState();
}

class _MySelfFieldState extends State<MySelfField> {
  final MyEdit.TextEditingController controller =
      MyEdit.TextEditingController();
  KeyController myVinController;
  FocusNode vinFocusNode = FocusNode();

  @override
  void initState() {
    super.initState();
    myVinController =
        KeyController(myTextController: controller, focusNode: vinFocusNode);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('自定义键盘'),
        ),
        bottomNavigationBar: MyKeyBoard(
          bottomSlot: Row(
            children: <Widget>[
              Expanded(
                child: Container(
                  alignment: Alignment.center,
                  height: 44,
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(4),
                  ),
                  child: Text(
                    '不符合VIN规范',
                  ),
                ),
              ),
              KeyItem(
                color: Colors.blue,
                text: '搜索',
                tap: () {},
              ),
            ],
          ),
          controller: controller,
          delete: () {
            myVinController.deleteOne();
          },
          tap: (String val) {
            myVinController.addText(val);
            setState(() {});
          },
        ),
        body: Column(children: [
          MyEnableTextField(
            focusNode: vinFocusNode,
            controller: controller,
            style: TextStyle(fontSize: 16),
          ),
          ElevatedButton(
            child: Text('删除'),
            onPressed: () {
              myVinController.deleteOne();
            },
          ),
          ElevatedButton(
            child: Text('添加文字'),
            onPressed: () {
              myVinController.addText('12');
            },
          ),
          ElevatedButton(
            child: Text('移除焦点'),
            onPressed: () {
              myVinController.removeFoucs();
            },
          ),
          ElevatedButton(
              child: Text('获取输入框'),
              onPressed: () {
                print(myVinController.text);
              })
        ]));
  }
}
